/*
 * @Descripttion: 
 * @version: 
 * @Author: wtzhang
 * @Date: 2021-06-30 14:11:02
 * @LastEditors: wtzhang
 * @LastEditTime: 2021-06-30 14:27:14
 */
/* 引入express框架 */
const express = require('express');
const app = express();
/* 引入cors */
const cors = require('cors');
app.use(cors());
/* 引入body-parser */
const bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

app.all('*', function (req, res, next) {
  if (!req.get('Origin')) return next();
  // use "*" here to accept any origin
  res.set('Access-Control-Allow-Origin', '*');
  res.set('Access-Control-Allow-Methods', 'GET');
  res.set('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type');
  // res.set('Access-Control-Allow-Max-Age', 3600);
  if ('OPTIONS' == req.method) return res.send(200);
  next();
});
app.get('/', (req, res) => {
  res.send('<p style="color:red">uni_appUpdate_api服务已启动</p>');
})
app.get('/app_update', (req, res) => {
  let appInfo = {
    appId: "__UNI__862DA51",
    version: "1.0.2",
  }
  let app_data = {}
  if (appInfo.version < "1.0.3") {
    app_data = {
      "isUpdate": true,
      "appid": appInfo.appId,
      "action": "sth", // 整包更新 = all ，应用资源独立升级 = sth
      "iOS": {
        "version": "iOS新版本号，如：1.0.0",
        "note": "iOS新版本描述信息，多行使用\n分割",
        "url": "Appstore路径，如：itms-apps://itunes.apple.com/cn/app/hello-h5+/id682211190?l=zh&mt=8"
      },
      "Android": {
        "version": "Android新版本号，如：1.0.1",
        "note": "Android新版本描述信息，多行使用\n分割",
        "url": "apk文件下载地址，如：http://www.dcloud.io/helloh5p/HelloH5.apk"
      }
    }
  } else {
    app_data = {
      "isUpdate": false
    }
  }
  appInfo = app_data
  res.json(app_data)
})
/* 监听端口 */
app.listen(8889, () => {
  console.log('listen:8889');
})